package com.tmc.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.entity.common.EthNotice;
import com.tmc.util.ObjectUtil;

@Repository
public class NoticeDaoImpl extends BaseDaoImpl<EthNotice> {

	public List<EthNotice> findByCon(ContextInfo context, EthNotice cond, int max) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from EthNotice c where c.enabledFlag = 'Y' ");
		if (cond.getSendTime() != null){
			sql.append(" and c.sendTime > :sendTime");
			params.put("sendTime", cond.getSendTime());
		}
		if (cond.getToSendTime() != null){
			sql.append(" and c.toSendTime < :toSendTime");
			params.put("toSendTime", cond.getToSendTime());
		}
		if (ObjectUtil.hasText(cond.getStatus())){
			sql.append(" and c.status = :status");
			params.put("status", cond.getStatus());
		}
		if (ObjectUtil.hasText(cond.getNoticeType())){
			sql.append(" and c.noticeType = :noticeType");
			params.put("noticeType", cond.getNoticeType());
		}
		if (cond.getSendTarget() != null){
			sql.append(" and c.sendTarget = :sendTarget");
			params.put("sendTarget", cond.getSendTarget());
		}
		sql.append(" order by c.lastUpdateDate ");
		return this.findList(max, sql, params);
	}
}
